package com.asuka.controller.admin;

import com.asuka.dto.TurnoverStatisticsDTO;
import com.asuka.result.Result;
import com.asuka.service.ReportService;
import com.asuka.vo.OrderReportVO;
import com.asuka.vo.TopVo;
import com.asuka.vo.TurnoverReportVO;
import com.asuka.vo.UserReportVO;
import io.swagger.annotations.Api;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RequestMapping("/admin/report")
@RestController
@Slf4j
@Api("数据统计")
public class ReportController {

    @Autowired
    private ReportService reportService;



    @GetMapping("/turnoverStatistics")
    public Result<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end){

        TurnoverReportVO tsvo = reportService.turnoverStatistics(begin,end);

        return Result.success(tsvo);
    }


    @GetMapping("/userStatistics")
    public Result<UserReportVO> userStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end){

        UserReportVO urvo = reportService.userStatistics(begin,end);

        return Result.success(urvo);
    }



    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> orderStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end ){

        OrderReportVO orvo = reportService.orderStatistics(begin,end);

        return Result.success(orvo);
    }


    @GetMapping("/top10")
    public Result<TopVo> topStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end ){

        TopVo tvo =reportService.topStatistics(begin,end);

        return Result.success(tvo);
    }



    @GetMapping("/export")
    public void export(HttpServletResponse response){
        reportService.exportExcel(response);
    }


}
